function e() {
    1 == a.data.info.is_dynamic ? wx.navigateTo({
        url: "/pages/emotimake/emotimake?micro_id=" + i + "&log_id=" + o
    }) : wx.navigateTo({
        url: "/pages/make/make?micro_id=" + i + "&log_id=" + o
    });
}

function t(e) {
    for (var t = a.data.rulelist, i = {
        pay_code: "",
        old_price: 0,
        now_price: 0
    }, o = 0; o < t.length; o++) if (e > 0) {
        if (t[o].pay_day > 0) {
            i = t[o];
            break;
        }
    } else if (t[o].pay_gold > 0) {
        i = t[o];
        break;
    }
    return i;
}

var a, i, o, n, r, c = require("../../utils/util.js"), s = getApp().globalData.url.imgurl;

Page({
    data: {
        imgurl: s,
        paywarp: !0,
        paytype: 1,
        curcode: "",
        old_price: 0,
        now_price: 0,
        tipshow: 0
    },
    onLoad: function(e) {
        i = e.mid, r = e.uid, a = this, c.getToken(function(e) {
            c.sendrequest("posterapi/getshare", "POST", {
                token: e,
                m_id: i,
                u_id: r
            }, function(e) {
                1 == e.status && a.setData({
                    shareimg: s + e.data.sharemes.shareimg
                });
            });
        });
    },
    onShow: function() {
        o = 0, n = 1, c.getToken(function(e) {
            c.sendrequest("posterapi/getposter", "POST", {
                token: e,
                id: i
            }, function(e) {
                1 == e.status && (a.setData({
                    info: e.data,
                    tipshow: e.data.tipshow
                }), e.data.ispay > 0 && (o = e.data.log_id));
            });
        }), c.sendrequest("payapi/payrule", "POST", "", function(e) {
            1 == e.status && a.setData({
                rulelist: e.data.paylist
            });
        });
    },
    onShareAppMessage: function(e) {
        return {
            title: "小婷海报",
            path: "pages/share/share?uid=" + r + "&&mid=" + i,
            success: function(e) {},
            fail: function(e) {}
        };
    },
    changetype: function(e) {
        var a = 1 == this.data.paytype ? 0 : 1, i = t(a);
        this.setData({
            paytype: a,
            old_price: i.old_price,
            now_price: i.now_price,
            curcode: i.pay_code
        });
    },
    more: function(e) {
        wx.reLaunch({
            url: "/pages/index/index"
        });
    },
    showpay: function(e) {
        var a = t(e.currentTarget.dataset.type);
        this.setData({
            paytype: e.currentTarget.dataset.type,
            paywarp: !1,
            old_price: a.old_price,
            now_price: a.now_price,
            curcode: a.pay_code
        });
    },
    selectpay: function(e) {
        this.setData({
            curcode: e.currentTarget.dataset.code
        });
        for (var t = a.data.rulelist, i = 0; i < t.length; i++) e.currentTarget.dataset.code == t[i].pay_code && this.setData({
            old_price: t[i].old_price,
            now_price: t[i].now_price
        });
    },
    closewarp: function(e) {
        this.setData({
            paywarp: !0
        });
    },
    checkboxChange: function(e) {
        n = e.detail.value[0] > 0 ? 1 : 0;
    },
    getsignpack: function(e) {
        if (n < 1) return wx.showToast({
            title: "请同意会员协议"
        }), !1;
        a.data.curcode && c.getToken(function(e) {
            c.sendrequest("payapi/createorder", "POST", {
                token: e,
                code: a.data.curcode
            }, function(e) {
                1 == e.status && wx.requestPayment({
                    timeStamp: e.data.timeStamp,
                    nonceStr: e.data.nonceStr,
                    package: "prepay_id=" + e.data.prepayId,
                    signType: "MD5",
                    paySign: e.data.paySign,
                    success: function(e) {
                        wx.showToast({
                            title: "支付成功",
                            icon: "success",
                            duration: 2e3
                        }), wx.reLaunch({
                            url: "/pages/poster/poster?micro_id=" + i
                        });
                    },
                    fail: function(e) {}
                });
            });
        });
    },
    changeme: function(n) {
        a.data.info.ispay > 0 && o > 0 ? e() : c.getToken(function(n) {
            wx.showLoading({
                title: "请求中",
                mask: !0
            }), c.sendrequest("posterapi/payposter", "POST", {
                token: n,
                id: i
            }, function(i) {
                if (wx.hideLoading(), 1 == i.status) o = i.data.log_id, e(); else if (3 == i.status) {
                    c.malert("金币不足");
                    var n = t(1);
                    a.setData({
                        paytype: 1,
                        paywarp: !1,
                        old_price: n.old_price,
                        now_price: n.now_price,
                        curcode: n.pay_code
                    });
                } else c.malert("网络错误");
            });
        });
    },
    collect: function(e) {
        c.addcollect(e.currentTarget.dataset.id);
    }
});